home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / earcd / grafica / ghostscript / 5.10 / gs_cmap.ps < prev    next >
Text File  |  1997-12-28  |  8KB  |  243 lines

  1. %    Copyright (C) 1995, 1996, 1997 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of Aladdin Ghostscript.
  3. % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  4. % or distributor accepts any responsibility for the consequences of using it,
  5. % or for whether it serves any particular purpose or works at all, unless he
  6. % or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  7. % License (the "License") for full details.
  8. % Every copy of Aladdin Ghostscript must include a copy of the License,
  9. % normally in a plain ASCII text file named PUBLIC.  The License grants you
  10. % the right to copy, modify and redistribute Aladdin Ghostscript, but only
  11. % under certain conditions described in the License.  Among other things, the
  12. % License requires that the copyright notice and this notice be preserved on
  13. % all copies.
  14.  
  15. % ProcSet for implementing CMap resources.
  16. % When this is run, systemdict is still writable.
  17.  
  18. % NOTE: Rearranged fonts are not implemented yet.
  19.  
  20. % ---------------- Public operators ---------------- %
  21.  
  22. % composefont doesn't appear in CMap files -- it's documented in
  23. % the "PostScript Language Reference Manual Supplement".
  24. /composefont        % <name> <cmap|cmapname> <fonts> composefont <font>
  25.  { 10 dict begin
  26.      1 index dup type /dicttype ne { /CMap findresource } if
  27.         /CMap exch def
  28.      /Encoding [ 0 1 4 index length 1 sub { } for ] def
  29.      /FDepVector 1 index def
  30.      /FMapType 9 def
  31.      /FontMatrix matrix def
  32.      /FontName 3 index def
  33.      /CMap load /WMode .knownget { /WMode exch def } if
  34.      /FontType 0 def
  35.    pop pop currentdict end /Font defineresource
  36.  } bind odef
  37.  
  38. % ---------------- CMap operators ---------------- %
  39.  
  40. 30 dict begin
  41.  
  42. % Our internal .CodeMaps structure is an array of two arrays: array 0
  43. % is the map for defined characters, array 1 is the map for notdefs.
  44. % Both are multi-level arrays indexed by the successive bytes of the
  45. % character code.  Each value is either a sub-array, null, a character name,
  46. % a CID (an integer), or a character code (expressed as a byte string).
  47. % All of the arrays are read-only after they have been built.
  48. %
  49. % Note that the code in zfcmap.c that constructs the C structures from
  50. % the PostScript structures has intimate knowledge of the above format.
  51.  
  52. /.getmap { .CodeMaps exch get } bind def
  53. /.putmap { .CodeMaps exch 3 -1 roll put } bind def
  54.  
  55. % ------ Font-level operators ------ %
  56.  
  57. /begincmap        % - begincmap -
  58.  { /.CodeMaps [256 array 256 array] def
  59.  } bind def
  60. /endcmap        % - endcmap -
  61.  { /.CodeMaps .CodeMaps .endmap def
  62.    /CodeMap null def        % for .buildcmap
  63.    currentdict end .buildcmap begin
  64.  } bind def
  65.  
  66. /begincodespacerange    % <count> begincodespacerange -
  67.  { pop mark
  68.  } bind def
  69. /endcodespacerange    % <code_lo> <code_hi> ... endcodespacerange -
  70.  { counttomark 2 idiv
  71.     { .CodeMaps { 3 copy .addcodespacerange pop } forall pop pop
  72.     } repeat pop
  73.  } bind def
  74.  
  75. /.addcodespacerange    % <code_lo> <code_hi> <map> .addcodespacerange -
  76.  { 2 index length 1 eq
  77.     { 2 { 3 -1 roll 0 get } repeat 1 exch
  78.        { 2 copy 0 put pop } for pop
  79.     }
  80.     { 2 index 0 get 1 3 index 0 get
  81.       6 -2 roll
  82.       2 { 1 1 index length 1 sub getinterval 6 1 roll } repeat
  83.         % Stack: lo hi map lo0 1 hi0
  84.        { 2 copy get null eq { 2 copy 256 array put } if
  85.          4 copy get .addcodespacerange pop
  86.        }
  87.       for pop pop pop
  88.     }
  89.    ifelse
  90.  } bind def
  91. /.endmap        % <map> .endmap <map>
  92.  { dup type /arraytype eq { dup { .endmap exch } forall astore readonly } if
  93.  } bind def
  94.  
  95. /usecmap        % <CMap_name> usecmap -
  96.  { /CMap findresource
  97.    dup length dict .copydict
  98.    currentdict end exch .copydict begin
  99.  } bind def
  100.  
  101. % ------ Rearranged font operators ------ %
  102.  
  103. /beginrearrangedfont    % <font_name> <font*> beginrearrangedfont -
  104.  {    (NOT IMPLEMENTED YET.\n) print flush
  105.  } bind def
  106. /endrearrangedfont    % - endrearrangedfont -
  107.  {    (NOT IMPLEMENTED YET.\n) print flush
  108.  } bind def
  109.  
  110. /usefont        % <fontID> usefont -
  111.  {    (NOT IMPLEMENTED YET.\n) print flush
  112.  } bind def
  113.  
  114. /beginusematrix        % <fontID> beginusematrix -
  115.  {    (NOT IMPLEMENTED YET.\n) print flush
  116.  } bind def
  117. /endusematrix        % <matrix> endusematrix -
  118.  {    (NOT IMPLEMENTED YET.\n) print flush
  119.  } bind def
  120.  
  121. % ------ Character name/code selector operators ------ %
  122.  
  123. /beginbfchar        % <count> beginbfchar -
  124.  { pop mark
  125.  } bind def
  126. /endbfchar        % <code> <to_code|charname> ... endbfchar
  127.  { 0 .getmap .endmapchar 0 .putmap
  128.  } bind def
  129.  
  130. /beginbfrange        % <count> beginbfrange -
  131.  { pop mark
  132.  } bind def
  133. /endbfrange        % <code_lo> <code_hi> <to_code|(charname*)> ...
  134.             %   endbfrange -
  135.  { 0 .getmap counttomark 3 idiv { .addbfrange } repeat 0 .putmap pop
  136.  } bind def
  137.  
  138. /.addbfrange        % <code_lo> <code_hi> <to_code|(charname*)> <map>
  139.             %   .addbfrange <map>
  140.  { 1 index type /stringtype eq
  141.     {  { dup length string copy dup dup length 1 sub 2 copy get 1 add put }
  142.       exch .addmaprange
  143.     }
  144.     { 2 dict begin exch /codes 1 index def 0 get exch
  145.        { codes dup length 1 sub 1 exch getinterval /codes 1 index def
  146.      dup length 0 gt { 0 get } if
  147.        }
  148.       exch .addmaprange end
  149.     }
  150.    ifelse exch pop
  151.  } bind def
  152.  
  153. % ------ CID selector operators ------ %
  154.  
  155. /begincidchar        % <count> begincidchar -
  156.  { pop mark
  157.  } bind def
  158. /endcidchar        % <code> <cid> ... endcidchar -
  159.  { 0 .getmap .endmapchar 0 .putmap
  160.  } bind def
  161.  
  162. /begincidrange        % <count> begincidrange -
  163.  { pop mark
  164.  } bind def
  165. /endcidrange        % <code_lo> <code_hi> <cid_base> ... endcidrange -
  166.  { 0 .getmap counttomark 3 idiv { { 1 add } exch .addmaprange exch pop } repeat
  167.    0 .putmap pop
  168.  } bind def
  169.  
  170. /.endmapchar        % -mark- <code> <value> ... <map> .endmapchar -
  171.  { counttomark 2 idiv
  172.     { 2 index 3 1 roll { } exch .addmaprange exch pop
  173.     } repeat exch pop
  174.  } bind def
  175.  
  176. /.addmaprange        % <code_lo> <code_hi> <value_base> <next_proc> <map>
  177.             %   .addcidrange <value_next> <map>
  178.  {    % We may be updating a (partly) read-only map from another CMap.
  179.     % If so, implement copy-on-write.
  180.    dup wcheck not { dup length array copy } if
  181.    4 index length 1 eq
  182.     { 2 { 5 -1 roll 0 get } repeat 1 exch
  183.        {    % Stack: value proc map code
  184.      2 copy 5 index put pop
  185.      3 -1 roll 2 index exec 3 1 roll
  186.        } for
  187.     }
  188.     { 4 index 0 get 1 5 index 0 get
  189.       8 -2 roll
  190.       2 { 1 1 index length 1 sub getinterval 8 1 roll } repeat
  191.         % Stack: lo hi next proc map lo0 1 hi0
  192.        { 6 copy get .addmaprange
  193.         % Stack: lo hi oldnext proc map i next submap
  194.      exch 6 1 roll 5 -1 roll pop
  195.         % Stack: lo hi next proc map i submap
  196.      3 copy put pop pop
  197.        }
  198.       for 5 -2 roll pop pop
  199.     }
  200.    ifelse exch pop
  201.  } bind def
  202.  
  203. % ------ notdef operators ------ %
  204.  
  205. /beginnotdefchar    % <count> beginnotdefchar -
  206.  { pop mark
  207.  } bind def
  208. /endnotdefchar        % <code> <cid> ... endnotdefchar -
  209.  { counttomark 2 idiv { 1 index exch .addnotdefrange } repeat pop
  210.  } bind def
  211.  
  212. /beginnotdefrange    % <count> beginnotdefrange -
  213.  { pop mark
  214.  } bind def
  215. /endnotdefrange        % <code_lo> <code_hi> <cid> ... endnotdefrange -
  216.  { counttomark 3 idiv { .addnotdefrange } repeat pop
  217.  } bind def
  218.  
  219. /.addnotdefrange    % <code_lo> <code_hi> <cid_base> .addnotdefrange -
  220.  { { } 1 .getmap .addmaprange 1 .putmap pop
  221.  } bind def
  222.  
  223. % ---------------- Resource category definition ---------------- %
  224.  
  225. currentdict end
  226.  
  227. languagelevel exch 2 .setlanguagelevel
  228.  
  229. /CMap /Generic /Category findresource dup length dict .copydict
  230. /Category defineresource pop
  231.     % We might have loaded CID font support already.
  232. /CIDInit /ProcSet 2 copy { findresource } .internalstopped
  233.     % An interior `stopped' might have reset VM allocation to local.
  234. true .setglobal
  235.  { pop pop 3 -1 roll }
  236.  { dup length 4 index length add dict .copydict 4 -1 roll exch .copydict }
  237. ifelse exch defineresource pop
  238.  
  239. .setlanguagelevel
  240.